<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background: #000;
            text-align: center
        }

        #c1 {
            background: #fff;
        }
    </style>

</head>

<body>
    <canvas id="c1" width="800" height="600">

    </canvas>
</body>
<script>
    let oC = document.getElementById('c1');
    let gd = oC.getContext('2d');       //图形上下文-绘图用的接口
    let l=50,t=50,w=100,h=100;
    function d2a(n){
        return n*Math.PI/180;
    }
    //矩形
    gd.save()    //保存
    gd.translate(100,100)
    
    gd.rotate(d2a(-10))
    
    gd.strokeRect(-50,-50,w,h)
    gd.fillStyle='rgba(255,0,0)'
    //恢复
    gd.restore()

    //思路
    //先画在画布顶点便左上的位置，然后旋转，然后指定偏移量，
    // 变换会叠加
    //变换之前 先save 后restore()

</script>

</html>